<?php
	include "./utils/dbfunctions.php";
	logToFile("indata init");
	
	if(!(isset($_POST['channelid']) && isset($_POST['map'])&& isset($_POST['enemy'])&& isset($_POST['lineup'])&& isset($_POST['reserve']) &&isset($_POST['fc']) && isset($_POST['pw'])))
	{
		logToFileAndDie("invalid post parameter");
	}
	//include "./utils/auth.php";
	mysql_connect("localhost","fc","keks")or logToFileAndDie("failed to Connect to Database");
	mysql_select_db("wottools") or logToFile("cannot select db") or die ("cannot select db");
	
	$kasse = getorcreateuserbywotaccountid(-1);
	//wotchannel
	$query = "INSERT INTO wottools.wotcwchannel( `CHANNELID`, `MAP`, `ENEMY`, `FC`) VALUES ( ".$_POST['channelid'].",'".$_POST['map']."','".$_POST['enemy']."',".$_POST['fc'].");";
	mysql_query($query) or logToFileAndDie("cannot insert wotcwchannel, query was: ".$query);
	
	
	
	
	//combatants
	logToFile("inserting lineup=".$_POST["lineup"]);
	$lineuparray = explode("|",$_POST["lineup"]);
	foreach($lineuparray as $lineupplayer)
	{
		if(!($lineupplayer===""))
		{
			$dbid = getorcreateuserbywotaccountid($lineupplayer);
			insertcombatant($dbid,$_POST['channelid'],0,$_POST["fc"]);
		}
	}
	
	logToFile("inserting reserve=".$_POST["reserve"]);
	$reservearray = explode("|",$_POST["reserve"]);	
	foreach($reservearray as $reserveplayer)
	{
		if(!($reserveplayer===""))
		{
			$dbid = getorcreateuserbywotaccountid($reserveplayer);
			insertcombatant($dbid,$_POST['channelid'],1,$_POST["fc"]);
		}
	}
?>





